﻿using Microsoft.EntityFrameworkCore;
using Coway.Ordering.Users;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.Modeling;
using Volo.Abp.Identity;
using Volo.Abp.Users.EntityFrameworkCore;
using Coway.Ordering.Orders;
using Coway.Ordering.Buyers;
using Coway.Ordering.Sellers;
using Coway.Ordering.Products;
using Coway.Ordering.PayOrders;

namespace Coway.Ordering.EntityFrameworkCore
{
    /* This is your actual DbContext used on runtime.
     * It includes only your entities.
     * It does not include entities of the used modules, because each module has already
     * its own DbContext class. If you want to share some database tables with the used modules,
     * just create a structure like done for AppUser.
     *
     * Don't use this DbContext for database migrations since it does not contain tables of the
     * used modules (as explained above). See OrderingMigrationsDbContext for migrations.
     */
    [ConnectionStringName("Default")]
    public class OrderingDbContext : AbpDbContext<OrderingDbContext>
    {
        public DbSet<AppUser> Users { get; set; }

        public DbSet<Product> Products { get; set; }

        public DbSet<Order> Orders { get; set; }

        public DbSet<OrderItem> OrderItems { get; set; }

        public DbSet<Buyer> Buyers { get; set; }
        
        public DbSet<Seller> Seller { get; set; }

        public DbSet<InstallationInfo> InstallationInfo { get; set; }

        public DbSet<CCRPayOrder> CCRPayOrder { get; set; }

        public DbSet<ACHPayOrder> ACHPayOrder { get; set; }

        public OrderingDbContext(DbContextOptions<OrderingDbContext> options)
            : base(options)
        {

        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            /* Configure the shared tables (with included modules) here */

            builder.Entity<AppUser>(b =>
            {
                b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "Users"); //Sharing the same table "AbpUsers" with the IdentityUser

                b.ConfigureByConvention();
                b.ConfigureAbpUser();

                /* Configure mappings for your additional properties
                 * Also see the OrderingEfCoreEntityExtensionMappings class
                 */
            });

            /* Configure your own tables/entities inside the ConfigureOrdering method */

            builder.ConfigureOrdering();
        }
    }
}
